<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/17
 * Time: 15:43
 */

namespace app\zucai\admin;
use app\admin\controller\Admin;
use app\common\builder\ZBuilder;
use think\Db;

class Card extends Admin
{
    //用户银行信息
    public function index(){
        $fla=Db::name('admin_user')->field('role')->where('id',is_signin())->find();
        if ($fla['role'] == 1) {
            $data_list = Db::name('admin_card')->where($this->getMap())
                ->order($this->getOrder('id DESC'))
                ->paginate();
            $fla=[
              0=>'禁用',
              1=>'启用',
            ];
            return ZBuilder::make('table')
                ->setTableName('user_card')
                ->addTopButtons('enable,disable') // 批量添加顶部按钮
                ->addRightButtons('enable,disable') // 批量添加顶部按钮
                ->addOrder('id')
                ->setSearch(['username' => '用户名', 'carnumber' => '银行卡号','nickname'=>'所属服务商'],'','',true)// 设置搜索参数
//                ->addRightButtons(['edit'=>array('title'=>'编辑','icon'=>'fa fa-pencil')])
                ->addColumns([
                    ['id', 'ID'],
                    ['nickname','所属服务商'],
                    ['username', '用户名'],
                    ['type', '类型'],
                    ['cardname', '银行'],
                    ['carnumber', '银行卡号'],
                    ['status', '状态', 'status'],
                    ['right_button', '操作', 'btn'],
                ])
                ->addFilter('username')
                ->addFilter('status',$fla)
                ->addFilter('type')
                ->addFilter('cardname')
                ->addFilter('carnumber')
                ->addFilter('states',config('cardtype'))
                ->setRowList($data_list)
                ->fetch();
        }else{
            $data_list = Db::name('admin_card')->where($this->getMap())
                ->where('aid',is_signin())
                ->order($this->getOrder('id DESC'))
                ->paginate();
            return ZBuilder::make('table')
                ->setTableName('user_card')
                ->addTopButtons('enable,disable') // 批量添加顶部按钮
                ->addRightButtons('enable,disable') // 批量添加顶部按钮
                ->addOrder('id')
                ->setSearch(['username' => '用户名', 'carnumber' => '银行卡号'])// 设置搜索参数
//                ->addRightButtons(['edit'=>array('title'=>'编辑','icon'=>'fa fa-pencil')])
                ->addColumns([
                    ['id', 'ID'],
                    ['user', '用户名'],
                    ['type', '类型'],
                    ['cardname', '银行类型'],
                    ['carnumber', '银行卡号'],
                    ['status', '状态', config('cardtype')],
                    ['right_button', '操作', 'btn'],
                ])
                ->addFilter('username')
                ->addFilter('type')
                ->addFilter('cardname')
                ->addFilter('carnumber')
                ->addFilter('states',config('cardtype'))
                ->setRowList($data_list)
                ->fetch();
        }

    }

}